package org.destiny.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = "/test2")
public class TestServiet2 extends HttpServlet {
    private static final long serialVersionUID = -5246754303115577337L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        // 设置返回的字符集
        resp.setCharacterEncoding("UTF-8");
        // 设置返回json
        resp.setContentType("application/json; charset=utf-8");
        PrintWriter out = resp.getWriter();
        // out.write("执行TestServlet2内doGet方法成功");
        out.println("执行TestServlet2内doGet方法成功");
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
